<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="com.hr.pojo.Upload"%>
<%@ page import="com.hr.pojo.Admin"%>
<%@ page import="com.hr.service.AdminService"%>
<%@ page import="com.hr.service.impl.AdminServiceImpl"%>
<%@ page import="com.hr.utils.*"%>
    <!--页面主要内容-->
            
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-toolbar clearfix">
                <form class="pull-right search-bar" method="get" action="#!" role="form">
                  <div class="input-group">
                    <div class="input-group-btn">
                      <input type="hidden" name="search_field" id="search-field" value="title">
                      <button class="btn btn-default dropdown-toggle" id="search-btn" data-toggle="dropdown" type="button" aria-haspopup="true" aria-expanded="false">
                      管理员 <span class="caret"></span>
                      </button>
                      <ul class="dropdown-menu">
                        <li> <a tabindex="-1" href="javascript:void(0)" data-field="title">标题</a> </li>
                        <li> <a tabindex="-1" href="javascript:void(0)" data-field="cat_name">栏目</a> </li>
                      </ul>
                    </div>
                    <input type="text" class="form-control" value="" name="keyword" placeholder="请输入名称">
                  </div>
                </form>
                <div class="toolbar-btn-action">
                  <a class="btn btn-primary m-r-5" href="main.jsp?method=indexUpload&servlet=UploadServlet"><i class="mdi mdi-plus"></i> 新增</a>
                  <a class="btn btn-danger" href="#!"><i class="mdi mdi-window-close"></i> 删除</a>
                </div>
              </div>
              <div class="card-body">
                
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th>
                          <label class="lyear-checkbox checkbox-primary">
                            <input type="checkbox" id="check-all"><span></span>
                          </label>
                        </th>
                        <th>上传用户</th>
                        <th>文件名称</th>
                        <th>文件简介</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody>
                    	<%
                    		int countPerPage=7;//每页数量
                    		int PageIndex=1;
							if(request.getParameter("pageIndex")!=null){
								PageIndex=Integer.parseInt(request.getParameter("pageIndex"));
							}
							List list=(List)request.getAttribute("uploadList");
							if(list!=null&&list.size()>0){
								int i=0;
								int pagei=0;
								if(PageIndex!=1){
									pagei=countPerPage*(PageIndex-1);
								}	
								Iterator it = list.iterator();
		   						while (it.hasNext() && i<countPerPage*PageIndex ) {
		   						Upload u = (Upload) it.next();
		   						if(i>=pagei){
						%>
                      <tr>
                        <td>
                          <label class="lyear-checkbox checkbox-primary">
                            <input type="checkbox" name="ids[]" value="1"><span></span>
                          </label>
                        </td>
                        <% 
                        		AdminService adminService=new AdminServiceImpl();
                        		Admin admin=adminService.findUserById(u.getUser());
                        		
                        %>
                        <td><%=StringUtil.notNull(admin.getUsername())%></td>
                        <td><%=StringUtil.notNull(u.getName())%></td>
                        <td><%=StringUtil.notNull(u.getContent())%></td>
                        <td>
                        <%	

        					String fileName=u.getUrl();
							String fileNameNow = fileName.substring(fileName.lastIndexOf("\\")+1);
	    					String[] strArray = fileNameNow.split("\\.");
        					int suffixIndex = strArray.length -1;
        					String now=strArray[suffixIndex];
        					fileNameNow=fileNameNow.substring(0,fileNameNow.lastIndexOf("."));
						%>
                          <div class="btn-group"><!-- href="main.jsp?method=toUpdatePage&id=<%=u.getId()%>&servlet=AdminServlet" -->
                            <a class="btn btn-xs btn-default" href="main.jsp?method=toUpdatePage&id=<%=u.getId()%>&servlet=AdminServlet"   title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>
                            <a class="btn btn-xs btn-default" href="UploadServlet?method=DownLoad&file=<%=fileNameNow%>&name=<%=java.net.URLEncoder.encode(u.getName())%>&now=<%=now %>" title="下载" data-toggle="tooltip"><i class="mdi mdi-eye"></i></a>
                            <a class="btn btn-xs btn-default" href="#!" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>
                          </div>
                          
                        </td>
                      </tr>
                      <%} i++;}}%>
                    </tbody>
                  </table>
                </div>
         		<ul class="pagination">
                  <li <%if(PageIndex==1){ %>class="disabled"<% }%> ><%if(PageIndex==1){ %><span>«</span><% }else{%><a href="main.jsp?method=listUpload&servlet=UploadServlet&pageIndex=<%=PageIndex-1%>">«</a><% }%> </li>
                 <%
         			int pageAll=0;
         			if(list.size()%countPerPage==0) {
						pageAll=list.size()/countPerPage;
					}else {
						pageAll=list.size()/countPerPage+1;
					}
         			for(int i=0;i<pageAll;i++){
         			if(i+1==PageIndex){
         		 %>       
         		 	<li class="active"><span><%=i+1%></span></li>
                  <%}else{%>  
                    <li><a href="main.jsp?method=listUpload&servlet=UploadServlet&pageIndex=<%=i+1%>"><%=i+1%></a></li>
				  <% }}%>   
                  <li class="disabled"><span>...</span></li>
                  <li <%if(PageIndex==pageAll){ %>class="disabled"<% }%> ><%if(PageIndex==pageAll){ %><span>»</span><% }else{%><a href="main.jsp?method=listUpload&servlet=UploadServlet&pageIndex=<%=PageIndex+1%>">»</a><% }%> </li>
                </ul>
              </div>
            </div>
          </div>
          
        </div>
        

      
    <!--End 页面主要内容-->
